package net.erl.objects.pattern.impl;

import net.erl.objects.pattern.ErlPattern;
import net.erl.objects.ErlTerm;

import java.util.Map;
import java.util.HashMap;

/**
 * Simple base pattern class. Use this as utility for implementations.
 */
public abstract class ErlPatternBase implements ErlPattern {

    /**
     * Utility: return initial vars or an empty map if null.
     * @param initialVars   A map of vars or null
     * @return              A map.
     */
    protected static Map<String, ErlTerm> ensureVars(Map<String,ErlTerm> initialVars) {
        return initialVars == null ? new HashMap<String, ErlTerm>(0) : initialVars;
    }


    public Map<String, ErlTerm> match(ErlTerm term) {
        return matchAndSet(term, null);
    }

}